<template>
	<view>
		<view class="bg-color"></view>
		<view class="login-Panel">
			<image class="logo" src="/static/logo.png"></image>
			<u-form :model="loginForm" ref="loginForm" >
				<u-form-item prop="userName" borderBottom>
					<u-input 
						v-model="loginForm.userName" 
						placeholder="请输登录账号" 
						prefixIcon="account" 
						prefixIconStyle="font-size:30px"
						border="none" 
						fontSize="16" 
					/>
				</u-form-item>
				<u-form-item prop="password" borderBottom>
					<u-input 
						v-if="pasts" 
						v-model="loginForm.password" 
						type="password" 
						placeholder="请输登录密码" 
						prefixIcon="lock" 
						border="none" 
						fontSize="16"
						prefixIconStyle="font-size:30px"
					>
						<template slot="suffix">
							<u-icon @click="pasts=!pasts" name="eye-fill" color="#e54d42" size="30" />
						</template>
					</u-input>
					<u-input 
						v-else v-model="loginForm.password" 
						type="text" 
						placeholder="请输登录密码" 
						prefixIcon="lock" 
						border="none" 
						fontSize="16" 
						suffixIcon="eye"
						prefixIconStyle="font-size:30px"
						@click="pasts=!pasts" 
					>
						<template slot="suffix">
							<u-icon @click="pasts=!pasts" name="eye" color="#e54d42" size="30" />
						</template>
					</u-input>
				</u-form-item>
				<view class="mt-60 flex justify-center">
					<u-checkbox :checked="isChecked" activeColor="#e54d42" size="16" label="同意" @change="event=>isChecked=event"></u-checkbox>
					<u-text type="primary" size="14" text="服务协议 | 隐私政策" />
				</view>
			</u-form>
			<view class="mt-80">
				<u-button @click="submit" color="#e54d42" size="large" :disabled="!isChecked">立即登录</u-button>
			</view>
		</view>
		<u-modal :show="showError" title="提示" :content='errorContent'></u-modal>
	</view>
</template>
<script>
	import {
		mapMutations 
	} from 'vuex'
	export default {
		data() {
			return {
				isChecked: false,
				pasts: true,
				showError:false,
				errorContent:'',
				errorType: 'toast',
				loginForm: {
					clientType: 2,
					userName: '',
					password: ''
				},
				rules: {
					userName: {
						required: true,
						message: '请输入账号',
						trigger: ['change', 'blur'],
					},
					password: {
						required: true,
						message: '请输入密码',
						trigger: ['change', 'blur'],
					}
				}
			};
		},
		onReady() {
			//如果需要兼容微信小程序，并且校验规则中含有方法等，只能通过setRules方法设置规则。
		},
		methods: {
			...mapMutations(['login']),
			submit() {
				let that = this
				that.$reqJsonPost('Login', that.loginForm).then(res => {
					if(res.code===0){
						that.login(res.data)
						uni.reLaunch({
							url: '/pages/index/index'
						})
					}else{
						that.errorContent = res.msg;
						that.showError = true;
					}
				})
			}
		}
	};
</script>
<style scoped lang="scss">
	.bg-color{
		width:100%;
		height: 600rpx;
		position: absolute;
		top: 0;
		left: 0;
		background: linear-gradient(to bottom right, #e14e60,#e2555d);
	}
	.login-Panel {
		width: 590rpx;
		padding:160rpx 60rpx 80rpx 60rpx;
		border-radius:10px;
		margin: 360rpx auto;
		background-color: #fff;
		box-shadow: 0 0 20rpx rgba(0, 0, 0, 0.08);
		position: relative;
		.logo {
			width: 240rpx;
			height: 240rpx;
			border-radius: 20rpx;
			display: block;
			position: absolute;
			top: -120rpx;
			left: 50%;
			transform: translateX(-50%);
		}
	}
</style>
